<?php defined('BASEPATH') OR exit('No direct script access allowed');

class repair extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		
		if (!$this->ion_auth->logged_in())
		{
			//redirect them to the login page
			redirect('auth/login', 'refresh');
		}
		elseif (!$this->ion_auth->is_admin())
		{
			//redirect them to the home page because they must be an administrator to view this	
			redirect('/', 'refresh');
		}
		$this->load->model('repair_model');
        $this->load->library('datatables');			
	}
	 function engineer_asssign()
	 {
	 $service_id=$_REQUEST['service_id'];
      $eng_id=  $_REQUEST['id_engineer'];
	  if(! empty($eng_id))
	  {
	    $eng_id=  $_REQUEST['id_engineer'];
	  }
	  else
	  {
	  $eng_id=$this->session->userdata('user_id');
	  
	  }
	
	  
	 $insert=array('case_id'=>$_REQUEST['case_id'],
	                 'docket_no'=>$_REQUEST['docket_no'],
					 'status_id'=>5,
					 'assigned_date'=>$_REQUEST['assign_date'],
					 'expected_date'=>$_REQUEST['expected_date'],
					 'engineer_id' =>$eng_id,);
			   
					$this->repair_model->engineer_assign($insert);
	                $this->repair_model->delete_diagnosis($service_id);
                    $this->repair_model->update_case_status($service_id,$eng_id);
               redirect('/admin/docket/view_notassigned','refresh');
	}
	
	
	public function view_allrepair()
	{
         $meta['page_title'] = 'ALL Repair';
		 $this->load->view('common/header',$meta);
	     $this->load->view('repair/all_repair');
		 $this->load->view('common/footer');		

	}public function view_completed_repair()
	{
	$meta['page_title'] = 'ALL Completed Repair';
    $this->load->view('common/header',$meta);
	$this->load->view('repair/completed_repair');
   $this->load->view('common/footer');
	}
	
	public function view_pending_repair()
	{ 
	
         $meta['page_title'] = 'ALL Pending Repair';
		 $this->load->view('common/header',$meta);
	     $this->load->view('repair/all_pending_repair');
		 $this->load->view('common/footer');		
     }
function get()
		{
		echo $this->repair_model->get_view();
		
		}	
function  nonwarranty_get()
		{
		echo $this->repair_model->get_nonwarrantyview();
		
		}	
	function get_completed()
		{
		echo $this->repair_model->get_view_completed();
		
		}
		function nonwarranty_completed()
		{
		echo $this->repair_model->nonwarranty_completed();
		
		}
		function get_pending()
		{
		echo $this->repair_model->get_view_pending();
		
		}
public function view_report($id)
{
    $customer_id=$this->repair_model->get_customer($id)->row();
    $this->data['cus']= $this->repair_model->get_cus( $customer_id->id)->row();
	$this->data['case']=$this->repair_model->get_case( $customer_id->id)->row();
	$this->data['repair']=$this->repair_model->get_repair_detail($this->data['case']->id)->row();
	$this->data['so']=$this->repair_model->get_so($this->data['case']->id);
	//$abc=$this->repair_model->count_old($this->data['so']->id);
	$this->data['expense']=$this->repair_model->get_expense_detail($this->data['case']->id)->row();
	$meta['page_title'] = 'View Detail Repair';
	$this->load->view('common/header',$meta);		
	$this->load->view('repair/detail_completed',$this->data);
	$this->load->view('common/footer');


}	
public function view_nonwarrantyreport($id)
{
    $customer_id=$this->repair_model->get_nonwarrantycustomer($id)->row();
    $this->data['cus']= $this->repair_model->get_cus( $customer_id->id)->row();
	$this->data['case']=$this->repair_model->get_nonwarrantycase( $customer_id->id)->row();
	$this->data['repair']=$this->repair_model->nonwarranty_repair_detail($this->data['case']->id)->row();
	$this->data['part']=$this->repair_model->get_part($this->data['case']->id);

	$meta['page_title'] = 'View Detail Repair';
	$this->load->view('common/header',$meta);		
	$this->load->view('nonwarranty/repair/detail_completed',$this->data);
	$this->load->view('common/footer');


}		   
public function view_reassigned()
{ 
$meta['page_title'] = 'ALL Reassigned Case';
    $this->load->view('common/header',$meta);
	$this->load->view('repair/reassigned_case');
   $this->load->view('common/footer');



}
function get_reassigned()
		{
		echo $this->repair_model->get_reassigned_view();
		
		}		   
public function view_assigned_repair()
{
$id=$this->session->userdata('user_id');
	$meta['page_title'] = 'New Assigned Repair';
	$this->load->view('common/header',$meta);		
	$this->load->view('repair/new_assigned_repair');
	$this->load->view('common/footer');

}	   
public function get_new()
{
 $id=$this->session->userdata('user_id');
	$at=$this->repair_model->get_views($id);
	print_r($at);

}	   
public function get_new_nonwarranty()
	{
	 $id=$this->session->userdata('user_id');
	$at=$this->repair_model->get_view_nonwarranty($id);
	print_r($at);
	
	}
public function ongoing_repair_view()
{
 $meta['page_title'] = 'Current Repair';
	$this->load->view('common/header',$meta);		
	$this->load->view('repair/current_repair_view');
	$this->load->view('common/footer');
}
function getcurrent()
		{ 
	   $id=$this->session->userdata('user_id');
		$at=$this->repair_model->get_current_view($id);
		print_r($at);
		
		}
		function getcurrent_nonwarranty()
		{ 
	   $id=$this->session->userdata('user_id');
		$at=$this->repair_model->get_currentnonwarranty_view($id);
		print_r($at);
		
		}
public function completed_repair()
{
$meta['page_title'] = 'ALL Completed Repair';
$this->load->view('common/header',$meta);		
$this->load->view('repair/all_repair_view');
$this->load->view('common/footer');
}		
function getall()
		{ 
	   $id=$this->session->userdata('user_id');
		$at=$this->repair_model->get_all_view($id);
		print_r($at);
		
		}
function nonwarranty_getall()
		{ 
	   $id=$this->session->userdata('user_id');
		$at=$this->repair_model->nonwarranty_getall($id);
		print_r($at);
		
		}
public function final_print($id)
{
$data['company_profile']=$this->repair_model->company_profile()->row();
$data['case_detail']= $this->repair_model->get_casedetail($id)->row();
$data['case_no']=$this->repair_model->get_case_no($id)->row();
$data['so']=$this->repair_model->get_so_detail($data['case_no']->id);
$data['access']=$this->repair_model->get_accesoriesdetail($data['case_detail']->id);   
$meta['page_title'] = 'Print Customer Receipt';
$this->load->view('common/header',$meta);		
$this->load->view('print/customer_receipt',$data);
$this->load->view('common/footer');
}
public function final_print_nonwarranty($id)
{
$data['company_profile']=$this->repair_model->company_profile()->row();
$data['case_detail']= $this->repair_model->get_non_casedetail($id)->row();
$data['case_no']=$this->repair_model->get_nonwarrantycase_no($id)->row();
$data['access']=$this->repair_model->get_accesoriesdetail($data['case_detail']->id);  
$data['so']=$this->repair_model->get_part_detail($data['case_no']->id);  
$meta['page_title'] = 'Print Customer Receipt';
$this->load->view('common/header',$meta);		
$this->load->view('print/customer_receipt',$data);
$this->load->view('common/footer');
}
public function deliver_customer($id)
{
$meta['page_title'] = 'Deliver To Customer';
$data['case_no']=$this->repair_model->get_case_no($id)->row();
$data['already_scan']=$this->repair_model->get_already_scan($data['case_no']->id)->row();
$data['case_detail']= $this->repair_model->get_casedetail($id)->row();
$this->load->view('common/header',$meta);		
$this->load->view('print/customer_deliver',$data);
$this->load->view('common/footer');

}
public function deliver_customer_nonwarranty($id)
{
$meta['page_title'] = 'Deliver To Customer';
$data['case_no']=$this->repair_model->get_nonwarrantycase_no($id)->row();
$data['already_scan']=$this->repair_model->get_already_scan_nonwarranty($data['case_no']->id)->row();
$data['case_detail']= $this->repair_model->get_non_casedetail($id)->row();
$this->load->view('common/header',$meta);		
$this->load->view('print/customer_deliver_nonwarranty',$data);
$this->load->view('common/footer');

}
	
	}
	?>